package com.recsmile.sgs.client.commonds.sync;

import com.recsmile.sgs.client.card.equips.Equipment;
import com.recsmile.sgs.client.commonds.GeneralGameUIClientCommand;
import com.recsmile.sgs.client.entity.Hero;
import com.recsmile.sgs.client.entity.InvalidPlayerCommandException;
import com.recsmile.sgs.client.ui.components.GamePanel;

public class SyncEquipGameUIClientCommand extends GeneralGameUIClientCommand {

	private static final long serialVersionUID = -9130336753281283554L;

	private final String name;
	private final Equipment equipment;
	
	public SyncEquipGameUIClientCommand(String name, Equipment equipment) {
		this.name = name;
		this.equipment = equipment;
	}
	
	@Override
	protected void execute(GamePanel<? extends Hero> panel) {
		try {
			if (panel.getContent().getSelf().getName().equals(name)) {
				panel.getContent().getSelf().equip(equipment);
			} else {
				panel.getContent().getPlayer(name).equip(equipment);
			}
		} catch (InvalidPlayerCommandException e) {
			e.printStackTrace();
		}
	}

}